zenXML
Straightforward C++ XML Processing
 All Classes Namespaces Functions Variables
Public Member Functions
zen::XmlElement Class Reference

An XML element. More...

#include <dom.h>

List of all members.

Public Member Functions

template<class String >
String getNameAs () const
 Retrieve the name of this XML element.
template<class T >
bool getValue (T &value) const
 Get the value of this element as a user type.
template<class T >
void setValue (const T &value)
 Set the value of this element.
template<class String , class T >
bool getAttribute (const String &name, T &value) const
 Retrieve an attribute by name.
template<class String , class T >
void setAttribute (const String &name, const T &value)
 Create or update an XML attribute.
template<class String >
void removeAttribute (const String &name)
 Remove the attribute with the given name.
template<class String >
XmlElement & addChild (const String &name)
 Create a new child element and return a reference to it.
template<class String >
const XmlElement * getChild (const String &name) const
 Retrieve a child element with the given name.
template<class String >
XmlElement * getChild (const String &name)
template<class String >
std::pair< ChildIterConst2,
ChildIterConst2 > 
getChildren (const String &name) const
 Access all child elements with the given name via STL iterators.
template<class String >
std::pair< ChildIter2, ChildIter2 > getChildren (const String &name)
std::pair< ChildIterConst,
ChildIterConst > 
getChildren () const
 Access all child elements sequentially via STL iterators.
std::pair< ChildIter, ChildIter > getChildren ()
XmlElement * parent ()
 Get parent XML element, may be nullptr for root element.
const XmlElement * parent () const
 Get parent XML element, may be nullptr for root element.

Detailed Description

An XML element.


Member Function Documentation

template<class String >
XmlElement& zen::XmlElement::addChild ( const String &  name)

Create a new child element and return a reference to it.

Template Parameters:
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
Parameters:
nameThe name of the child element to be created.
template<class String , class T >
bool zen::XmlElement::getAttribute ( const String &  name,
T &  value 
) const

Retrieve an attribute by name.

Template Parameters:
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
TString-convertible user data type: e.g. any string class, all built-in arithmetic numbers
Parameters:
nameThe name of the attribute to retrieve.
valueThe value of the attribute converted to T.
Returns:
"true" if value was retrieved successfully.
template<class String >
const XmlElement* zen::XmlElement::getChild ( const String &  name) const

Retrieve a child element with the given name.

Template Parameters:
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
Parameters:
nameThe name of the child element to be retrieved.
Returns:
A pointer to the child element or nullptr if none was found
template<class String >
XmlElement* zen::XmlElement::getChild ( const String &  name)
See also:
getChild
template<class String >
std::pair<ChildIterConst2, ChildIterConst2> zen::XmlElement::getChildren ( const String &  name) const

Access all child elements with the given name via STL iterators.

      auto iterPair = elem.getChildren("Item");
      std::for_each(iterPair.first, iterPair.second,
            [](const XmlElement& child) { ... });
Parameters:
nameThe name of the child elements to be retrieved.
Returns:
A pair of STL begin/end iterators to access all child elements sequentially.
template<class String >
std::pair<ChildIter2, ChildIter2> zen::XmlElement::getChildren ( const String &  name)
See also:
getChildren
std::pair<ChildIterConst, ChildIterConst> zen::XmlElement::getChildren ( ) const

Access all child elements sequentially via STL iterators.

      auto iterPair = elem.getChildren();
      std::for_each(iterPair.first, iterPair.second,
            [](const XmlElement& child) { ... });
Returns:
A pair of STL begin/end iterators to access all child elements sequentially.
std::pair<ChildIter, ChildIter> zen::XmlElement::getChildren ( )
See also:
getChildren
template<class String >
String zen::XmlElement::getNameAs ( ) const

Retrieve the name of this XML element.

Template Parameters:
StringArbitrary string class: e.g. std::string, std::wstring, wxString, MyStringClass, ...
Returns:
Name of the XML element
template<class T >
bool zen::XmlElement::getValue ( T &  value) const

Get the value of this element as a user type.

Template Parameters:
TArbitrary user data type: e.g. any string class, all built-in arithmetic numbers, STL container, ...
Returns:
"true" if Xml element was successfully converted to value, cannot fail for string-like types
template<class String >
void zen::XmlElement::removeAttribuStringArbitrary string class: e.g. std::string, std::wstring, wxString, MyStringClass, ...
)

Remove the attribute with the given name.

Template Parameters:
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
template<class String , class T >
void zen::XmlElement::setAttributeringArbitrary string class: e.g. std::string, std::wstring, wxString, MyStringClass, ...
const T &  value  )

Create or update an XML attribute.

Template Parameters:
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
TString-convertible user data type: e.g. any string-like type, allclass="">
Template Parameters:
TArbitrary user data type: e.g. any string class, all built-in arithmetic numbers, STL container, ...
valueThe value to set.
template<class T >
void zen::XmlElement::setValue ( const T &  value)

Set the value of this element.

Template Parameters:
TArbitrary user data type: e.g. any string-like type, all built-in arithmetic numbers, STL container, ...